package work.huangxin.share.service.impl;

import com.alibaba.fastjson.JSON;
import kotlin.jvm.internal.SerializedIr;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import work.huangxin.share.domain.schedule.ClassSchedule;
import work.huangxin.share.domain.schedule.ClassScheduleNote;
import work.huangxin.share.domain.schedule.ClassSecheduleVO;
import work.huangxin.share.mapper.ClassScheduleMapper;
import work.huangxin.share.service.ClassScheduleService;
import work.huangxin.share.util.common.HttpClientUtil;
import work.huangxin.share.util.status.ResponseData;

import java.util.HashMap;
import java.util.List;

/**
 * @author: 张锦标
 * @date: 2023/4/17 19:35
 * ClassScheduleServiceImpl类
 */
@Service
public class ClassScheduleServiceImpl implements ClassScheduleService {

    @Autowired
    private ClassScheduleMapper classScheduleMapper;
    @Override
    public void getAllClassSchedulesWithNotes(Long userId) {

    }

    @Override
    public void getThisWeekClassSchedules(Long userId) {

    }

    @Override
    public void getWeather(String city) {

    }

    @Override
    public void uploadNote(ClassScheduleNote classScheduleNote) {

    }

    @Override
    public void updateNote(ClassScheduleNote classScheduleNote) {

    }

    @Override
    public void deleteNote(Long noteId) {

    }

    @Override
    public List<ClassSchedule> getClassScheduleByClazzName(String clazzName) {
        return classScheduleMapper.selectByClazzName(clazzName);
    }

    @Override
    public List<ClassSecheduleVO> getClassScheduleWithNoteByClazzName(Integer userId, String clazzName) {
        return classScheduleMapper.selectByClazzNameWithNote(Long.valueOf(userId), clazzName);
    }

    @Override
    public int  getClazzName(String s) {
        return classScheduleMapper.selectClazzName(s);
    }

    @Override
    public Long insertWithUserId(ClassSecheduleVO classSecheduleVO) {
        classScheduleMapper.insertWithUserId(classSecheduleVO);
        ClassSchedule cs = new ClassSchedule();
        BeanUtils.copyProperties(classSecheduleVO,cs);
        ClassSchedule classSchedule = classScheduleMapper.selectOne(cs);
        Long csId = classSchedule.getId();
        return csId;
    }

    @Override
    public HashMap getBlessing() {
        HashMap<Object, Object> map = new HashMap<>();
        String result = HttpClientUtil.doGet("https://v1.hitokoto.cn/");
        HashMap hashMap = JSON.parseObject(result, map.getClass());
        return hashMap;
    }
}
